package com.ocom.payconfig.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.card.EntityPackageData;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.request.callpackage.GetPackagePayRequest;
import com.ocom.common.request.callpackage.GetPackagePayResponse;
import com.ocom.common.utils.DateUtil;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payconfig.dao.IDaoPackageData;
import com.ocom.payconfig.service.PackageDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PackageDataServiceImpl extends ServiceImpl<IDaoPackageData, EntityPackageData> implements PackageDataService {

    @Autowired
    private IDaoPackageData daoPackageData;

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId")
    public List<GetPackagePayResponse> getPackagePay(Long comId, GetPackagePayRequest request) {
        if (null != request.getEndDate()) {
            request.setEndDate(DateUtil.addDays(request.getEndDate(), 1));
        }
        return daoPackageData.getPackagePay(comId, request.getPId(), request.getBeginDate(), request.getEndDate(), request.getSize());
    }
}
